<template>
    <div>
      <van-button type="primary">获取数据</van-button>
    </div>
  </template>
  <script>
  import {
    computed,
    defineComponent,
    getCurrentInstance,
    onMounted,
    reactive,
    ref,
    toRefs,
  } from "vue";
  export default defineComponent({
    name: "demo",
    props: "",
    components: "",
    setup (props, context) {
      //引用全局变量
      const { proxy } = getCurrentInstance()
      let state = reactive({
        buttonName: "点击发送请求",
      });
      //dom挂载后
      onMounted(() => {
        sendHttp();
      });
  
      function sendHttp () {
        console.log(proxy)
        proxy.$axios.post("/register", {})
          .then((res) => {
            //请求成功
            console.log(res)
          })
      }
      return {
        ...toRefs(state),
        sendHttp,
      };
    },
  });
  </script>
  